package com.app.bimo.library_db.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.app.bimo.library_db.ReadChapterRecordConvert;
import java.util.List;

import com.app.bimo.library_db.ReadTimeRecord;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "READ_TIME_RECORD".
*/
public class ReadTimeRecordDao extends AbstractDao<ReadTimeRecord, Long> {

    public static final String TABLENAME = "READ_TIME_RECORD";

    /**
     * Properties of entity ReadTimeRecord.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Novelid = new Property(1, String.class, "novelid", false, "NOVELID");
        public final static Property Uuid = new Property(2, String.class, "uuid", false, "UUID");
        public final static Property Chapter = new Property(3, String.class, "chapter", false, "CHAPTER");
        public final static Property CreatTime = new Property(4, long.class, "creatTime", false, "CREAT_TIME");
        public final static Property EndTime = new Property(5, long.class, "endTime", false, "END_TIME");
        public final static Property Status = new Property(6, int.class, "status", false, "STATUS");
    }

    private final ReadChapterRecordConvert chapterConverter = new ReadChapterRecordConvert();

    public ReadTimeRecordDao(DaoConfig config) {
        super(config);
    }
    
    public ReadTimeRecordDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"READ_TIME_RECORD\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"NOVELID\" TEXT," + // 1: novelid
                "\"UUID\" TEXT," + // 2: uuid
                "\"CHAPTER\" TEXT," + // 3: chapter
                "\"CREAT_TIME\" INTEGER NOT NULL ," + // 4: creatTime
                "\"END_TIME\" INTEGER NOT NULL ," + // 5: endTime
                "\"STATUS\" INTEGER NOT NULL );"); // 6: status
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"READ_TIME_RECORD\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ReadTimeRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String novelid = entity.getNovelid();
        if (novelid != null) {
            stmt.bindString(2, novelid);
        }
 
        String uuid = entity.getUuid();
        if (uuid != null) {
            stmt.bindString(3, uuid);
        }
 
        List chapter = entity.getChapter();
        if (chapter != null) {
            stmt.bindString(4, chapterConverter.convertToDatabaseValue(chapter));
        }
        stmt.bindLong(5, entity.getCreatTime());
        stmt.bindLong(6, entity.getEndTime());
        stmt.bindLong(7, entity.getStatus());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ReadTimeRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String novelid = entity.getNovelid();
        if (novelid != null) {
            stmt.bindString(2, novelid);
        }
 
        String uuid = entity.getUuid();
        if (uuid != null) {
            stmt.bindString(3, uuid);
        }
 
        List chapter = entity.getChapter();
        if (chapter != null) {
            stmt.bindString(4, chapterConverter.convertToDatabaseValue(chapter));
        }
        stmt.bindLong(5, entity.getCreatTime());
        stmt.bindLong(6, entity.getEndTime());
        stmt.bindLong(7, entity.getStatus());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ReadTimeRecord readEntity(Cursor cursor, int offset) {
        ReadTimeRecord entity = new ReadTimeRecord( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // novelid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // uuid
            cursor.isNull(offset + 3) ? null : chapterConverter.convertToEntityProperty(cursor.getString(offset + 3)), // chapter
            cursor.getLong(offset + 4), // creatTime
            cursor.getLong(offset + 5), // endTime
            cursor.getInt(offset + 6) // status
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ReadTimeRecord entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setNovelid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setUuid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setChapter(cursor.isNull(offset + 3) ? null : chapterConverter.convertToEntityProperty(cursor.getString(offset + 3)));
        entity.setCreatTime(cursor.getLong(offset + 4));
        entity.setEndTime(cursor.getLong(offset + 5));
        entity.setStatus(cursor.getInt(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ReadTimeRecord entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ReadTimeRecord entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ReadTimeRecord entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
